package Sort;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author Liangyaoyun
 */
public  class insertsort {
    public void Sort(int[] nums){
        int tmp;
        //因为手中必需要有一张牌来比较，所以下标从一开始
        for (int i = 1; i <= nums.length-1; i++) {
            //j是新抽的牌，i是上一张抽的牌
            for (int j = i; j>0&&nums[j]<nums[j-1] ; j--) {
                    tmp=nums[j];
                    nums[j]=nums[j-1];
                    nums[j-1]=tmp;
            }
        }

    }

    @Test
    public  void main(){
        insertsort selectSort=new insertsort();
        int[] nums=new int[]{6,7,4,3,2,8,9,1,0,5};
        selectSort.Sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
